
package com.example.util;

import com.alibaba.ttl.TransmittableThreadLocal;
import org.springframework.lang.Nullable;
import org.springframework.web.context.request.RequestAttributes;

public class CustomRequestContextHolder{

	private static final ThreadLocal<RequestAttributes> transmittableRequestAttributesHolder = new TransmittableThreadLocal<>();

	public static void resetRequestAttributes() {
		transmittableRequestAttributesHolder.remove();
	}

	public static void setRequestAttributes(@Nullable RequestAttributes attributes) {
		if (attributes == null) {
			resetRequestAttributes();
		} else {
			transmittableRequestAttributesHolder.set(attributes);
		}
	}

	@Nullable
	public static RequestAttributes getRequestAttributes() {
		return transmittableRequestAttributesHolder.get();
	}

}
